<template>
    <el-dialog title="新建规则" :visible.sync="show">
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="规则名称" :rules="[{ required: true, message: '请输入规则名称', trigger: 'blur' }]">
                <el-input v-model="form.title" placeholder="请输入规则名称"></el-input>
            </el-form-item>
            <el-form-item label="规则详情" :rules="[{ required: true, message: '请输入规则详情', trigger: 'blur' }]">
                <el-input v-model="form.detail" type="textarea" :autosize="{ minRows: 6, maxRows: 20 }" placeholder="请输入规则详情"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="onSubmit" :loading="submiting">提交</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: "RuleCreateDialog",
        data(){
            return {
                show:false,
                submiting:false,
                form:{
                    title:'',
                    detail:'',
                },
            }
        },
        methods:{
            init(){
                this.show = true;
                this.form = {
                    title:'',
                    detail:'',
                }
            },
            onSubmit(){
                let that = this;
                this.submitting = true;
                this.post('/api/activity/rules/create',this.form).then(result=> {
                    this.submitting = false;
                    if(result.code === 0){
                        this.$message.success(result.msg);
                        that.rules = result.data;
                        that.show = false;
                        that.$emit('refresh');
                    }else{
                        this.$message.error(result.msg);
                    }
                }).catch(e=>{
                    console.log(e);
                    this.$message.error('处理异常');
                    this.submitting = false;
                })
            }

        },
    }
</script>

<style scoped>

</style>